/*
 * Copyright(C) 2009, kesalin All rights reserved.
 * 
 * File name : DropSource.h
 * Brief     : Implement of IDropSource.
 * Version   : 1.0
 * Author    : kesalin@gmail.com
 * Date      : 2009-6-5
 */

#pragma once

namespace DragDrop {

// IDropSourceImpl
class IDropSourceImpl : public IDropSource {

	HCURSOR m_hCursor;

public:

	IDropSourceImpl() : m_hCursor(0)
	{
	}

	void SetupCursor(HCURSOR h)
	{
		m_hCursor = h;
	}

	STDMETHOD(QueryContinueDrag)(
		BOOL  fEscapePressed,
		DWORD grfKeyState)
	{
		if (fEscapePressed 
			|| (grfKeyState & MK_RBUTTON) == MK_RBUTTON
			|| (grfKeyState & MK_MBUTTON) == MK_MBUTTON) {

			return DRAGDROP_S_CANCEL;
		}

		if ((grfKeyState & MK_LBUTTON) == 0) {
			return DRAGDROP_S_DROP;
		}

		return S_OK;
	}

	STDMETHOD(GiveFeedback)(DWORD dwEffect)
	{
#if 1
		if (m_hCursor != 0) {
			SetCursor(m_hCursor);
			return S_OK;
		}
#else
		if (m_hCursor != 0) {
			if ((dwEffect & DROPEFFECT_COPY) != 0 ||
				(dwEffect & DROPEFFECT_MOVE) != 0 ||
				(dwEffect & DROPEFFECT_LINK) != 0) {
				SetCursor(m_hCursor);
				return S_OK;
			}
		}
#endif

		return DRAGDROP_S_USEDEFAULTCURSORS;
	}

}; // IDropSourceImpl

} // namespace DragDrop

